<?php
function filter_link($title, $url) {
	$url = link_exists_url($url);
	$title = link_exists_name($title);
	if (($url == 0) && ($title == 0)) {
		return 1;
	} else return 0;	
}

function link_exists_name($title) {
	$query = "SELECT links.title FROM `links` WHERE links.title = '{$title}'";
//	echo paragraph($query);
	$result = mysql_query($query) or die ( mysql_error() );
	if (mysql_num_rows($result) > 0) {
		echo breakline("Link name already exists");
		// notifier::add("Title already exists", "error"); 
		// return 1;
	} else return 0;
}

function link_exists_url($url) {
	$query = "SELECT links.url FROM `links` WHERE links.url = '{$url}'";	
	$result = mysql_query($query) or die ( mysql_error() );
	if (mysql_num_rows($result) > 0) {
		echo breakline("URL already exists");
		// notifier::add("URL already exists", "error"); 
		// return 1;
	} else return 0;
}

function checklength($string, $length = 4) {
	$strlen = strlen($string);
	if ($strlen < $length) {
		echo breakline("Length too short");
		return 0;
	} else {
		return 1;
	}
}
?>